clear
capture log close
set more off
set mem 500m


****

use data_pt_pop_1891, clear

*** Fix manchester and salford
replace loc="manchester" if loc=="salford"
count
collapse (sum) pop, by(loc year)
count

sort loc
merge loc using data_town_cotton_shr_1851
tab _merge
keep if _merge==3
drop _merge


** LHS var
gen log_pop=log(pop)

sort loc year
gen gr_pop=log_pop-log_pop[_n-1] if loc==loc[_n-1]


** RHS
gen cotton10=0
replace cotton10=1 if shr_cot>.1

gen other_tex_shr=shr_wool+shr_other_tex
gen other_tex=0
replace other_tex=1 if other_tex_shr>.1 & shr_cot<.1


keep pop gr_pop shr_cot cotton10 other_tex loc year
reshape wide pop gr_pop, i(loc) j(year)
drop gr_pop1841
gsort -shr_cot
outsheet using results_table_3.csv, comma replace
